package com.destin.basic.config;


import com.destin.basic.template.MinioTemplate;
import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 文件处理配置类
 * @author destin
 * @since 2020-12-07
 */
@Configuration
@EnableConfigurationProperties({OssProperties.class})
@Slf4j(topic = "=> ")
public class OssConfiguration {

	private OssProperties ossProperties;

	public OssConfiguration(final OssProperties ossProperties) {
		this.ossProperties = ossProperties;
	}

	@Configuration
	class MinioConfig {
		@Bean
		public MinioClient minioClient() throws InvalidPortException, InvalidEndpointException {
			return new MinioClient(ossProperties.getEndpoint(), ossProperties.getAccessKey(), ossProperties.getSecretKey());
		}

		@Bean
		public MinioTemplate minioTemplate(MinioClient minioClient) {
			log.info("MinioTemplate init start... {}", minioClient);
			return new MinioTemplate(ossProperties.getBucketName(), ossProperties.getEndpoint(), minioClient);
		}
	}


}

